import { reqGoodDetailInfoData } from '@/api'

const state = {
    goodDetailInfo: {}
}

const actions = {
    async getGoodDetailInfoData({ commit }, id) {
        const result = await reqGoodDetailInfoData(id)
        // console.log('getGoodDetailInfoData', result.data);
        if (result.code === 200) {
            commit('SAVE_GOOD_DETAIL_INFO_DATA', result.data)
        } else {
            console.log(result.message);
        }
    }
}

const mutations = {
    SAVE_GOOD_DETAIL_INFO_DATA(state, payload) {
        state.goodDetailInfo = payload
    }
}
const getters = {
    categoryView(state) {
        return state.goodDetailInfo.categoryView || {}
    },
    skuInfo(state) {
        return state.goodDetailInfo.skuInfo || {}
    },
    spuSaleAttrList(state) {
        return state.goodDetailInfo.spuSaleAttrList || {}
    }

}

export default {
    namespaced: true,
    state,
    actions,
    mutations,
    getters
}